package
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.TimerEvent;
	import flash.text.TextField;
	import flash.utils.Timer;

	public class CommandButton extends Button
	{
		private var textSprite:Sprite;
		private var textSprInit:Boolean = true;
		private var text:TextField;
		private var building:Building;
		private var timer:Timer;
		
		public function CommandButton(m:Menu){
			super(m);
		}
		
		override protected function send(e:Event):void{
			renderSprite.command(filename);
			menu.hide();
		}
		
		public function beginDisplayResource(b:Building):void{
			building = b;
			if(textSprInit){
				textSprite = new Sprite();
				text = Formatting.newSubtitle(""+b.getResource(),0xFFFFFF,(bitmap.width/2)-22,(bitmap.height/2)+5);	
				textSprite.addChild(text);
				textSprInit = false;
				addChild(textSprite);
			}
			timer = new Timer(1000/15);
			timer.addEventListener(TimerEvent.TIMER,tick);
			timer.start();
		}
		private function tick(e:Event):void{
			text.text=""+building.getResource();		
		}
		public function finishDisplayResource():void{
			text.text="";
			
			timer.stop();
			timer.removeEventListener(TimerEvent.TIMER,tick);
		}
	}
}